﻿/* 
 * author: www.cnblogs.com/luminji
 * date  : 2012/01/26
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Luminji.Infrastructure.UnitOfWork;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using Luminji.Core.Web.Cookie;

namespace Luminji.Exam.Model.Users
{
    public class ExamUserService 
    {
        private IExamUserRepository _userRepository;

        public ExamUserService(IExamUserRepository userRepository)
        {
            _userRepository = userRepository;
        }

        public IList<ExamUser> FindAll(string name)
        {
            return _userRepository.Find(name);
        }

        public LoginState CheckUser(string name, string password)
        {
            var users = _userRepository.Find(name);
            if (users.Count == 0)
            {
                return LoginState.UserNotExsisted;
            }
            if (users[0].UserKey != password)
            {
                return LoginState.PasswordWrong;
            }
            return LoginState.WellCome;
        }

        public void SetLoginStates(string name)
        {
                
        }

        public void AddUser(ExamUser user)
        {
            _userRepository.Add(user);
            _userRepository.UnitOfWork.Commit();
        }
        
    }
}
